package com.qianbao.controller;


import com.qianbao.domain.Account;
import com.qianbao.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;


@Controller
@RequestMapping("/account")
public class AccountController {

    @Autowired
    private AccountService accountService;

    @RequestMapping("/findAll")
    public String findAll(Model model){
        System.out.println("控制器查询所有的方法");
        List<Account> accounts = accountService.findAll();
        model.addAttribute("accounts",accounts);
        return "list";
    }

    @RequestMapping("/saveAccount")
    public void saveAccount(Account account, HttpServletRequest request, HttpServletResponse response){

        System.out.println("控制器保存账户的方法");
        accountService.saveAccount(account);

        try {
            response.sendRedirect(request.getContextPath() + "/account/findAll");
        } catch (IOException e) {
            e.printStackTrace();
        }

    }





}
